/*
 *  Copyright (c) 2023-2025 苏州棱镜七彩信息科技有限公司 (Suzhou PrismAurora Information Technology Co.,Ltd)
 *  sbom-generate is licensed under Mulan PSL v2.
 *  You can use this software according to the terms and conditions of the Mulan PSL v2.
 *  You may obtain a copy of Mulan PSL v2 at:
 *           http://license.coscl.org.cn/MulanPSL2
 *  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *  See the Mulan PSL v2 for more details.
 * */
package com.ljqc.impl.sbom;

import com.ljqc.abs.sbom.SBomGenerate;
import com.ljqc.entity.DocMetaInfo;
import com.ljqc.entity.FileInfo;
import com.ljqc.entity.SWIDDocument;

import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @ClassName SPDXTagValueGenerate
 * @Description
 * @Date 2025/3/14 13:46
 * @Version V1.0
 **/
public class SWIDGenerate implements SBomGenerate<SWIDDocument, FileInfo> {
    private static final Logger LOGGER = Logger.getLogger(SWIDGenerate.class.getName());

    @Override
    public SWIDDocument generateByInfoList(List<FileInfo> infoList, DocMetaInfo docMetaInfo) {
        LOGGER.log(Level.INFO, "开始生成SWID文档，文件信息数量：{0}", infoList.size());
        
        SWIDDocument swidDocument = new SWIDDocument();
        String tagId = "urn:uuid:" + UUID.randomUUID();
        swidDocument.setTagId(tagId);
        LOGGER.log(Level.FINE, "设置文档标签ID：{0}", tagId);
        String documentName = docMetaInfo.getDocName();
        String name = documentName == null || documentName.trim().length() == 0 ? tagId : documentName;
        swidDocument.setName(name);
        LOGGER.log(Level.FINE, "设置文档名称：{0}", name);
        
        swidDocument.setFiles(infoList);
        LOGGER.log(Level.FINE, "添加文件信息列表，包含 {0} 个文件", infoList.size());
        
        LOGGER.log(Level.INFO, "SWID文档生成完成，文档名称：{0}", name);
        return swidDocument;
    }
}
